/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PaymentConfirmationView.java
 *
 * Created on Apr 28, 2010, 5:16:45 PM
 */
package ticketmaster.presentation.customer.purchase;

import ticketmaster.businessobject.PurchaseType;
import ticketmaster.common.CardType;
import ticketmaster.common.OrderType;
import ticketmaster.common.PurchaseTypes;
import ticketmaster.dataobject.Bankcard;
import ticketmaster.dataobject.Order;
import ticketmaster.presentation.HomeView;
import ticketmaster.presentation.customer.CustomerBasePanel;
import ticketmaster.presentation.customer.PremiumCustomerPanel;
import ticketmaster.presentation.customer.WelcomeView;
import ticketmaster.util.DateTimeHelper;
import ticketmaster.util.StringHelper;

/**
 *
 * @author Wei Liu
 */
public class PaymentConfirmationView extends CustomerBasePanel
{

    private Order order;
    private Bankcard bankcard;
    private String message;

    /** Creates new form PaymentConfirmationView */
    public PaymentConfirmationView(Order order, Bankcard bankcard)
    {
        this.order = order;
        this.bankcard = bankcard;
        initComponents();
        initContent();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        btnContinue = new javax.swing.JButton();
        lblDescription = new javax.swing.JLabel();
        lblAmount = new javax.swing.JLabel();
        lblStatus = new javax.swing.JLabel();
        lblDate = new javax.swing.JLabel();
        lblReference = new javax.swing.JLabel();
        lblMethod = new javax.swing.JLabel();
        lblAccountNumber = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ticketmaster.TicketMasterApp.class).getContext().getResourceMap(PaymentConfirmationView.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 25, 330, 30));

        jLabel2.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, -1, -1));

        jLabel3.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 280, -1, -1));

        jLabel4.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 360, -1, -1));

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 320, -1, -1));

        jLabel6.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N
        add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 400, -1, -1));

        jLabel7.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N
        add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, -1, -1));

        jLabel8.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N
        add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 160, -1, -1));

        btnContinue.setFont(resourceMap.getFont("btnContinue.font")); // NOI18N
        btnContinue.setText(resourceMap.getString("btnContinue.text")); // NOI18N
        btnContinue.setName("btnContinue"); // NOI18N
        btnContinue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnContinueActionPerformed(evt);
            }
        });
        add(btnContinue, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 490, 150, 50));

        lblDescription.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        lblDescription.setText(resourceMap.getString("lblDescription.text")); // NOI18N
        lblDescription.setName("lblDescription"); // NOI18N
        add(lblDescription, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 120, -1, -1));

        lblAmount.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        lblAmount.setText(resourceMap.getString("lblAmount.text")); // NOI18N
        lblAmount.setName("lblAmount"); // NOI18N
        add(lblAmount, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 160, -1, -1));

        lblStatus.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        lblStatus.setText(resourceMap.getString("lblStatus.text")); // NOI18N
        lblStatus.setName("lblStatus"); // NOI18N
        add(lblStatus, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 240, -1, -1));

        lblDate.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        lblDate.setText(resourceMap.getString("lblDate.text")); // NOI18N
        lblDate.setName("lblDate"); // NOI18N
        add(lblDate, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 280, -1, -1));

        lblReference.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        lblReference.setText(resourceMap.getString("lblReference.text")); // NOI18N
        lblReference.setName("lblReference"); // NOI18N
        add(lblReference, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 320, -1, -1));

        lblMethod.setFont(resourceMap.getFont("lblMethod.font")); // NOI18N
        lblMethod.setText(resourceMap.getString("lblMethod.text")); // NOI18N
        lblMethod.setName("lblMethod"); // NOI18N
        add(lblMethod, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 360, -1, -1));

        lblAccountNumber.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        lblAccountNumber.setText(resourceMap.getString("lblAccountNumber.text")); // NOI18N
        lblAccountNumber.setName("lblAccountNumber"); // NOI18N
        add(lblAccountNumber, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 400, -1, -1));
    }// </editor-fold>//GEN-END:initComponents

    private void btnContinueActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnContinueActionPerformed
    {//GEN-HEADEREND:event_btnContinueActionPerformed
        if (PurchaseType.getPurchaseType() == PurchaseTypes.Normal)
        {
            WelcomeView wv = new WelcomeView();
            this.getPnlParent().removeAll();
            this.getPnlParent().add(wv);
            this.getPnlParent().validate();
            this.getPnlParent().repaint();
            wv.setPnlParent(this.getPnlParent());
        }
        if (PurchaseType.getPurchaseType() == PurchaseTypes.New)
        {
            HomeView hv = new HomeView();
            hv.setVisible(true);
            if (this.getMainFrame() != null)
            {
                this.getMainFrame().setVisible(false);
            }
        }
        else if (PurchaseType.getPurchaseType() == PurchaseTypes.Upgrade || PurchaseType.getPurchaseType() == PurchaseTypes.Continue)
        {
            PremiumCustomerPanel pca = new PremiumCustomerPanel();
            this.getPnlParent().removeAll();
            this.getPnlParent().add(pca);
            this.getPnlParent().validate();
            this.getPnlParent().repaint();
            pca.setPnlParent(this.getPnlParent());
        }
    }//GEN-LAST:event_btnContinueActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnContinue;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel lblAccountNumber;
    private javax.swing.JLabel lblAmount;
    private javax.swing.JLabel lblDate;
    private javax.swing.JLabel lblDescription;
    private javax.swing.JLabel lblMethod;
    private javax.swing.JLabel lblReference;
    private javax.swing.JLabel lblStatus;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the order
     */
    public Order getOrder()
    {
        return order;
    }

    /**
     * @param order the order to set
     */
    public void setOrder(Order order)
    {
        this.order = order;
    }

    private void initContent()
    {
        OrderType type;
        CardType cardType = null;
        if (OrderType.TicketFee.ordinal() == order.getOrderType())
        {
            type = OrderType.TicketFee;
        }
        else
        {
            type = OrderType.YearlyFee;
        }
        if (CardType.Visa.ordinal() == getBankcard().getCardType())
        {
            cardType = CardType.Visa;
        }
        else if (CardType.MasterCard.ordinal() == getBankcard().getCardType())
        {
            cardType = CardType.MasterCard;
        }
        else if (CardType.AmericanExpress.ordinal() == getBankcard().getCardType())
        {
            cardType = CardType.AmericanExpress;
        }
        this.lblDescription.setText(type.toString());
        this.lblAmount.setText(StringHelper.formatPrice(order.getCost()));
        this.lblAccountNumber.setText(StringHelper.hideCardNumber(bankcard.getCardNumber()));
        this.lblDate.setText(StringHelper.getDate(DateTimeHelper.getCurrentDateTime().toString()));
        this.lblMethod.setText(cardType.toString());
        this.lblReference.setText(String.valueOf(order.getOrderID()));
        this.lblStatus.setText("Approved: Payment has been processed successfully.");
    }

    /**
     * @return the bankcard
     */
    public Bankcard getBankcard()
    {
        return bankcard;
    }

    /**
     * @param bankcard the bankcard to set
     */
    public void setBankcard(Bankcard bankcard)
    {
        this.bankcard = bankcard;
    }
}
